<template>
  <div class="login-root">
    <el-card style="width: 350px; margin: 100px auto;">
      <el-form>
        <el-form-item label="手机号">
          <el-input v-model="mobile" />
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="password" type="password" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
      <div v-if="error" style="color: red;">{{ error }}</div>
    </el-card>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const mobile = ref('')
const password = ref('')
const error = ref('')

const mockAccounts = [
  {
    id: '1',
    mobile: '13800000001',
    password: '123456',
    name: '张三',
    staffNo: '1001',
    roles: ['普通客服'],
    groups: ['售前组'],
    status: 'active',
    permissions: ['chat', 'ticket', 'profile']
  },
  {
    id: '2',
    mobile: '13800000002',
    password: '654321',
    name: '李四',
    staffNo: '1002',
    roles: ['组长'],
    groups: ['售后组'],
    status: 'inactive',
    permissions: ['chat', 'ticket', 'profile', 'report']
  }
]

function login() {
  console.log('login called', mobile.value, password.value)
  // 只取手机号后11位
  const pureMobile = mobile.value.replace(/[^\d]/g, '').slice(-11)
  const user = mockAccounts.find(acc => acc.mobile === pureMobile && acc.password === password.value)
  if (!user) {
    error.value = '手机号或密码错误'
    return
  }
  error.value = ''
  window.localStorage.setItem('currentStaff', JSON.stringify(user))
  router.push('/service/dashboard')
}
</script>
<style scoped>
.login-root {
  min-height: 100vh;
  background: #f5f5f5;
}
</style> 